<template>
  <div class="container">
    <div @click="tabLeft">
      <img class="tab" src="../../static/left-cate.png" />
    </div>
    <div v-for="(item, index) in list.slice(0, 6)" :key="index">
      <div class="cate-item" @click="changeList(index)">
        <div class="item-img">
          <img :src="item.img" />
        </div>
        <div class="item-title">{{ item.title }}</div>
      </div>
    </div>
    <div @click="tabRight">
      <img class="tab" src="../../static/right-cate.png" />
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    cateList: {
      type: Array,
      default: [],
    },
  },
  mounted() {
    this.list = this.cateList;
  },
  data() {
    return {
      list: [],
    };
  },
  methods: {
    tabLeft() {
      let arr = this.list.splice(0, 1);
      this.list = [...this.list, ...arr];
      this.$emit("cateTitle");
    },
    changeList(index) {
      if (index === 0) return;
      let arr = this.list.splice(0, index);
      this.list = [...this.list, ...arr];
      this.$emit("cateTitle");
    },
    tabRight() {
      let fin = this.list[this.list.length - 1];
      console.log(fin);
      this.list.splice(this.list.length - 1, 1);
      this.list.unshift(fin);
      this.$emit("cateTitle");
    },
  },
};
</script>

<style scoped>
.container {
  margin-top: 0.1rem;
  width: 70%;
  left: 50%;
  position: relative;
  transform: translateX(-50%);
  border-radius: 0.1rem;
  background-color: #fff;
  padding: 1.3% 0%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tab {
  width: 80%;
  height: 80%;
}
.cate-item {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.cate-item img {
  width: 90%;
  height: 90%;
  margin-left: 4%;
}
.item-title {
  line-height: 0.2rem;
}
</style>

